import 'package:faker/i18n/i18n.dart';
import 'package:faker/models/article.dart';
import 'package:faker/utils/prase_util.dart';
import 'package:faker/utils/route_util.dart';
import 'package:flutter/material.dart';
import 'package:flutter_slidable/flutter_slidable.dart';

class ItemArticleList extends StatefulWidget {
  /// TODO实体
  final Article item;

  final Function delete;

  /// 滑动删除Controller
  SlidableController slidableController;

  ItemArticleList({
    this.item,
    this.slidableController,
    this.delete,
  });

  @override
  State<StatefulWidget> createState() {
    return new _ItemArticleListState();
  }
}

class _ItemArticleListState extends State<ItemArticleList> {
  @override
  Widget build(BuildContext context) {
    var item = widget.item;
    Color c = Theme.of(context).primaryColorLight;
    SlidableController slidableController = widget.slidableController;
    return Material(
      color: Theme.of(context).backgroundColor,
      shape: new RoundedRectangleBorder(
        side: const BorderSide(
          width: 0.382,
          style: BorderStyle.solid,
        ),
        //每个角落的半径
        borderRadius: new BorderRadius.circular(6.0),
      ),
      child: Slidable(
        controller: slidableController,
        actionPane: SlidableDrawerActionPane(),
        actionExtentRatio: 0.25,
        child: InkWell(
          onTap: () {
            RouteUtil.toWebView(context, item.title, item.link);
          },
          child: Column(
            children: <Widget>[
              Row(
                children: <Widget>[
                  Expanded(
                    child: Container(
                      padding: EdgeInsets.fromLTRB(16, 8, 16, 8),
                      child: Column(
                        children: <Widget>[
                          Container(
                            alignment: Alignment.topLeft,
                            padding: EdgeInsets.fromLTRB(0, 2, 0, 2),
                            child: Text(
                              item.title,
                              style: TextStyle(
                                  fontSize: 16,
                                  color: Theme.of(context).textSelectionColor),
                              maxLines: 1,
                              overflow: TextOverflow.ellipsis,
                              textAlign: TextAlign.left,
                            ),
                          ),
                          Container(
                            alignment: Alignment.topLeft,
                            padding: EdgeInsets.fromLTRB(0, 8, 0, 2),
                            child: Text(
                              PraseUtil.removeTag(htmlString: item.description),
                              style: TextStyle(
                                  fontSize: 15, color: Color(0xFF757575)),
                              maxLines: 3,
                              overflow: TextOverflow.ellipsis,
                              textAlign: TextAlign.left,
                            ),
                          ),
                          Container(
                            alignment: Alignment.topLeft,
                            padding: EdgeInsets.fromLTRB(0, 8, 0, 2),
                            child: Text(
                              item.pubDate == null ? "木有日期" : item.pubDate,
                              style: TextStyle(
                                  fontSize: 15, color: Color(0xFF757575)),
                            ),
                          )
                        ],
                      ),
                    ),
                  ),
                ],
              ),
              Divider(height: 1),
            ],
          ),
        ),
        secondaryActions: <Widget>[
          IconSlideAction(
            caption: S.of(context).delete,
            color: Theme.of(context).backgroundColor,
            icon: Icons.cancel,
            onTap: () {
              ///删除;
              widget.delete(item.guid);
            },
          ),
        ],
      ),
    );
  }
}
